<?php
/**
 * Mission Summary Page
 * Maintain all master mission master data in a single view
 * 
 * @package jobs
 */
use Fox\Html\TextArea;
use Fox\Html\Interval;
use Fox\Html\Block;
use Hive\Mission;
use Fox\Generator;
use Fox\Html\Header\Content,Fox\Html\Button,Fox\Html\Screen;

$xview = Xview::instance();
/* $mission Hive\Mission */
$mission = Xview::instance()->component('missions', 'object');
$data = $mission->getData();
// Customizing
$customizing = Hive\Mission\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'missions','act'=>'detail'));
// Parse Data to save Job Information
$data['kn_number_year_left'] = $data['kn_number_year_min'];
$data['kn_number_year_right'] = $data['kn_number_year_max'];
$data['salary_left'] = $data['salary_low'] ;
$data['salary_right'] = $data['salary_high'];
$data['bonus_left'] = $data['bonus_low'];
$data['bonus_right'] = $data['bonus_high'];
		
$screen = new Screen('eMission','update',null,true);
$blInfo = Xview::instance()->component('missions', 'info');
$screen->add($blInfo);
// Salary Block
$bkSalary = new Block('bSalary',Msg(Hive::BUNDLE,Hive::MISSION_SALARY_BLOCK));
$bkSalary->add(new Interval(array('mission_salary','salary')));
$bkSalary->add(new Interval(array('mission_bonus','bonus')));
$bkSalary->add(new TextArea(array('job_advantages','tags'),null,null,null,2));
$bkSalary->collapsed(false);
$screen->add($bkSalary);
$screen->initialize($data);
// Skills
$bkSkills = new Block('bSkills',Msg(Hive::BUNDLE,Hive::MISSION_SKILLS_BLOCK));
$gSkills = $xview->component('missions', 'skills');
$bkSkills->add($gSkills);
$screen->add($bkSkills);

if($screen->submitted())
{
	$inputs = $screen->get();
	if(!$screen->errors())
	{
		
		// Parse Data to save Job Information
		$inputs['kn_number_year_min'] = $inputs['kn_number_year_left'];
		$inputs['kn_number_year_max'] = $inputs['kn_number_year_right'];
		$inputs['salary_low'] = $inputs['salary_left'];
		$inputs['salary_high'] = $inputs['salary_right'];
		$inputs['bonus_low'] = $inputs['bonus_left'];
		$inputs['bonus_high'] = $inputs['bonus_right'];
		try {
			$mission->setFields($inputs);
			$mission->prepareUpdate(Hive\Mission::CHANGE_DEFAULT);
			if($mission->update())
			{
				Fox\Message::Success(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_UPDATE,$mission->label()));
			}
			else
			{
				Fox\Message::Information(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_NO_UPDATE,$mission->label()));
			}
		}
		catch(Fox\Object\Exception\Save $e)
		{
			Fox\Message::Error($e->getMessage());
		}
	}
	echo $xview->messages();
	exit;
}
$title = new Content('personnal','Detail');
?>
<div id="detailArea">
	<div class="page-header clearfix">
		<?php echo $title->render();?>
	</div>
	<div class="">
		<div class="mbs">
			<?php echo $screen->display();?>
		</div>
	</div>
</div>